package com.coldchain.message;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.coldchain.message.core.constant.QueryType;

/**
 * @ClassName config
 * @Description TODO
 * @Author fangliai
 * @Date 2018/9/20 17:40
 * @Vesion 1
**/
 @Configuration
public class QueryConfig  {


    @Bean
    public Queue newOrderQueueMessage() {
        return new Queue(QueryType.NEW_ORDER_QUERY,true);
    }

    @Bean
    public Queue helpOrderQueueMessage() {
        return new Queue(QueryType.HELP_ORDER_QUERY,true);
    }
    @Bean
    public Queue dispatchQueueMessage() {
        return new Queue(QueryType.DISPATCH_QUERY,true);
    }
    @Bean
    public Queue deliveryQueueMessage() {
        return new Queue(QueryType.DELIVERY_QUERY,true);
    }
    @Bean
    public Queue completeQueueMessage() {
        return new Queue(QueryType.COMPLETE_QUERY,true);
    }
    @Bean
    public Queue smsQueueMessage() {
        return new Queue(QueryType.CODE);
    }


    @Bean
    public Queue carLocationQueueMessage() {
        return new Queue(QueryType.CAR_LOCATION_QUERY,true);
    }

    @Bean
    public FanoutExchange newOrderFanoutExchange() {
        return new FanoutExchange(QueryType.NEW_ORDER_QUERY + "—exchange");
    }
    @Bean
    public FanoutExchange helpOrderFanoutExchange() {
        return new FanoutExchange(QueryType.HELP_ORDER_QUERY + "—exchange");
    }
    @Bean
    public FanoutExchange dispatchOrderFanoutExchange() {
        return new FanoutExchange(QueryType.DISPATCH_QUERY + "_exchange");
    }
    @Bean
    public FanoutExchange deliveryOrderFanoutExchange() {
        return new FanoutExchange(QueryType.DELIVERY_QUERY + "_exchange");
    }
    @Bean
    public FanoutExchange completeOrderFanoutExchange() {
        return new FanoutExchange(QueryType.COMPLETE_QUERY + "_exchange");
    }

    @Bean
    public FanoutExchange smsFanoutExchange() {
        return new FanoutExchange(QueryType.CODE+"_exchange");
    }

    @Bean
    public FanoutExchange carLocationFanoutExchange() {
        return new FanoutExchange(QueryType.CAR_LOCATION_QUERY+"_exchange");
    }
    @Bean
    public Binding newOrderFanoutBinding() {
        return BindingBuilder.bind(newOrderQueueMessage()).to(newOrderFanoutExchange());
    }
    @Bean
    public Binding  helpOrderFanoutBinding() {
        return BindingBuilder.bind(helpOrderQueueMessage()).to(helpOrderFanoutExchange());
    }
    @Bean
    public Binding dispatchOrderFanoutBinding() {
        return BindingBuilder.bind(dispatchQueueMessage()).to(dispatchOrderFanoutExchange());
    }
    @Bean
    public Binding deliveryOrderFanoutBinding() {
        return BindingBuilder.bind(deliveryQueueMessage()).to(deliveryOrderFanoutExchange());
    }
    @Bean
    public Binding completeOrderFanoutBinding() {
        return BindingBuilder.bind(completeQueueMessage()).to(completeOrderFanoutExchange());
    }

    @Bean
    public Binding smsFanoutBinding() {
        return BindingBuilder.bind(smsQueueMessage()).to(smsFanoutExchange());
    }

    @Bean
    public Binding carLocationFanoutBinding() {
        return BindingBuilder.bind(carLocationQueueMessage()).to(carLocationFanoutExchange());
    }
}
